# 抖码算法，让算法学习变得简单有趣
# 作者：老汤
import sys

data = str(input()).split(" ")
nums, sum_ = [0] * 10, 0
for i in range(10):
    nums[i] = int(data[i])
    sum_ += nums[i]

res = sys.maxsize
for i in range(6):
    for j in range(i + 1, 7):
        for k in range(j + 1, 8):
            for l in range(k + 1, 9):
                for m in range(l + 1, 10):
                    tmp = nums[i] + nums[j] + nums[k] + nums[l] + nums[m]
                    res = min(res, abs(sum_ - 2 * tmp))

print(res)